#include "sample.h"

Sample* Sample::_instance = 0;

Sample* Sample::Instance()
{
	if (_instance == 0)
	{
		_instance = new Sample();
	}
	return _instance;
}

Sample::Sample()
{
	_mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32,
		ALLEGRO_CHANNEL_CONF_2);
	_voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16,
		ALLEGRO_CHANNEL_CONF_2);
	al_attach_mixer_to_voice(_mixer, _voice);
	ifstream infile;
	infile.open("gameinformation/Sample.txt");
	if (!infile)
	{
		cout << "can't open the sample information" << endl;
	}
	string temp;
	while (getline(infile, temp))
	{
		_arrSample.push_back(al_load_audio_stream(temp.c_str(), 4, 1024));
	}
}

void Sample::playSample(int i)
{
	al_set_audio_stream_playing(_arrSample[i], true);
	al_set_audio_stream_playmode(_arrSample[i], ALLEGRO_PLAYMODE_ONCE);
	al_rewind_audio_stream(_arrSample[i]);
	al_attach_audio_stream_to_mixer(_arrSample[i], _mixer);
}